<template>
<div>
    <el-table
        ref="multipleTable"
        :data=CheckUserList
        tooltip-effect="dark"
        style="width: 100%"
        @select="handleSelectionChange">
        <el-table-column
        type="selection"
        width="55">
        </el-table-column>
        <el-table-column
        label="序号"
        width="120">
        <template slot-scope="scope">{{ scope.row.UserID }}</template>
        </el-table-column>
        <el-table-column
        prop="UserName"
        label="账户"
        width="120">
        </el-table-column>
        <el-table-column
        prop="RealName"
        label="姓名"
        show-overflow-tooltip>
        </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {MenuCheckUser} from '@/api/jurisdiction'

  export default {
    props:{
      CheckUserList:{
        type:Array
      },
      checkUser:{
        type:Array
      },
      MenuId:{
        type:Number
      }
    },
    data() {
      return {
        newVal:[],
        multipleSelection: [],
      }
    },
    watch:{
      CheckUserList(val){
        this.toggleSelection(val)
      }
    },
    methods: {
       toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$nextTick(()=>{
              this.$refs.multipleTable.toggleRowSelection(row,row.IsChecked);
            })
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val,e) {
        console.log(!e.IsChecked)
        if(this.MenuId==-1){
          alert('请选择菜单')
        }else{
          let id=''
        val.forEach((el)=>{
          id+=el.UserID+","
        })
        id=(id.substring(id.length-1)==',')?id.substring(0,id.length-1):id;
        id.substring(0,id.length)
        let check=!e.IsChecked
        MenuCheckUser({permissionID:this.MenuId,strUserID:id,check:check}).then((res)=>{
            // alert(res.Message)
            })
          }
        }
    }
  }
</script>